/*
 * Copyright (c) 2018-2999 湖南洛云网络科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.discount.platform.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.enums.ProdStatusEnums;
import com.yami.shop.bean.model.Product;
import com.yami.shop.bean.param.ProductParam;
import com.yami.shop.common.i18n.I18nMessage;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.discount.comment.model.Discount;
import com.yami.shop.discount.comment.service.DiscountService;
import com.yami.shop.security.multishop.util.SecurityUtils;
import com.yami.shop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;


/**
 *
 * @author lgh on 2018/11/21.
 */
@RestController
@RequestMapping("/admin/discountProd")
public class DiscountProdController {

    @Autowired
    private DiscountService discountService;

    @Autowired
    private ProductService productService;

    /**
	 * 获取信息
	 */
	@GetMapping("/info/{discountId}")
	public ResponseEntity<IPage<Product>> info(@PathVariable("discountId") Long discountId, ProductParam product, PageParam<Product> page){
		Discount discount = discountService.getById(discountId);
		product.setLang(I18nMessage.getDbLang());
		product.setShopId(SecurityUtils.getShopUser().getShopId());
		if(Objects.equals(discount.getSuitableProdType(),0)){
			product.setStatus(ProdStatusEnums.NORMAL.getValue());
			IPage<Product> products = productService.pageByLang(page,product);
			return ResponseEntity.ok(products);
		}else{
			IPage<Product> products = discountService.pageProdByDiscount(page,product,discount);
			return ResponseEntity.ok(products);
		}
	}



}
